<?php

include '../../db.php';
$connect = pg_connect($connectionString);
if (!$connect) {
    echo "connect : A connection to the server could not be established!";
    return false;
}

$params = array();
array_push($params, pg_escape_string(strtoupper($_POST["name"])));
array_push($params, pg_escape_string($_POST["code"]));
array_push($params, pg_escape_string($_POST["type"]));
array_push($params, pg_escape_string($_POST["cost"]));
array_push($params, pg_escape_string($_POST["price"]));
array_push($params, pg_escape_string($_POST["quantity"]));
array_push($params, pg_escape_string($_POST["category_id"]));
array_push($params, pg_escape_string($_POST["subcategory_id"]));
array_push($params, pg_escape_string($_POST["brand_id"]));
array_push($params, pg_escape_string($_POST["model_id"]));
array_push($params, pg_escape_string($_POST["scaffold_id"]));
array_push($params, pg_escape_string($_POST["file_id"]));
array_push($params, pg_escape_string($_POST["position_id"]));
array_push($params, pg_escape_string($_POST["unit_id"]));

$stmt = pg_prepare($connect, "create_warehouse_product", "INSERT INTO warehouse_product(name,code,type,cost,price,quantity,category_id,subcategory_id,brand_id,model_id,scaffold_id,file_id,position_id,unit_id) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14);");
$result = pg_execute($connect, "create_warehouse_product", $params);

if (!$result) {
    die("Error in SQL query: " . pg_last_error());
}
pg_free_result($result);
pg_close($connect);